package org.eclipse.stp.policy_builder.model.source;

import org.eclipse.stp.policy_builder.model.exceptions.DescriptorException;
import org.eclipse.stp.policy_builder.model.source.types.AbstractParamType;
import org.eclipse.stp.policy_builder.model.source.types.BoolParameter;
import org.eclipse.stp.policy_builder.model.source.types.StringParameter;
import org.eclipse.stp.policy_builder.model.source.types.UrlParameter;

public class SourceParameter extends SupportedTypes{
	private String defaultValue,value,paramName;
	private AbstractParamType paramType;
	
	
	
	
	public SourceParameter(String defaultValue,String type) throws DescriptorException{
		this.defaultValue = defaultValue;
		if(TYPES.contains(type.toLowerCase())){
			setParameterType(type);
		}
		else{
			throw new DescriptorException("Invalid type declared in the descriptor.[TYPE :] "+type+" not supported...");
		}
		
	}
	
	public SourceParameter(String name,String defaultValue,String type) throws DescriptorException{
		this(defaultValue,type);
		this.paramName = name ;
				
	}
	
	public String getParameterValue(){
		if(value!=null){
			return value;
		}
		else if(defaultValue!=null){
			return defaultValue;
		}
		
		return null;
	}
	
	public String getParameterName(){
		return paramName;
	}
	
	public void setValue(String value){
		this.value = value;
	}
	
	public AbstractParamType getParameterType(){
		return paramType;
	}
	
	
	
	private void setParameterType(String type){
		if(type.equals(T_STRING)){
			paramType = new StringParameter(type) ;
		}
		else if(type.equals(T_URL)){
			paramType = new UrlParameter(type);
		}
		else if(type.equals(T_BOOLEAN)){
			paramType = new BoolParameter(type);
		}
	}
}
